package org.robotfish.geometry;

import org.ejml.simple.SimpleMatrix;
import org.robotfish.utils.SVGDocument;
import org.w3c.dom.Comment;
import org.w3c.dom.Element;

/**
 * Transforms points according to the x coordinate of the point
 * @author Mart
 */
public class TransformationX extends TransformationFork<TransformationArc> {
	
	public TransformationX(double start) {
		this.coordinateValue = start;
	}
	
	@Override
	public int getCoordinate() {
		return 1;
	}

	public void clearArcs() {
		segments.clear();
	}
	
	@Override
	public SimpleMatrix getRay() {
		return segments.get(0).getRay();
	}

	@Override
	public void appendSVGElements(SVGDocument doc, Element parent, double arcLength) {
		Comment comment = doc.createComment(getClass().getName()+".appendSVGElements: arcs="+segments.size());
		parent.appendChild(comment);
        
        
		Transformation current = segments.get(0);
    	Element text = doc.createText(getRay(), "y="+SVGDocument.DoubleToString3p(coordinateValue), doc.getColour(8), 3);
        parent.appendChild(text);

        for (int i=1;i<segments.size();i++) {
        	Transformation next = segments.get(i);
    		// create a group
            Element group = doc.createGroup();
            parent.appendChild(group);		
            current.appendSVGElements(doc, group, next.coordinateValue-current.coordinateValue);
            current = next;
        }
		// create a group
        Element group = doc.createGroup();
        parent.appendChild(group);		
        current.appendSVGElements(doc, group, arcLength);

	}
	
}
